package huoye.shops.huoye.operation.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.codeideology.android.AXIFragmentPagerAdapter;
import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.PullToRefreshActivity;
import huoye.shops.base.UserManager;
import huoye.shops.huoye.mine.model.ProductInfo;
import huoye.shops.huoye.operation.fragment.ManageProductFragment;
import huoye.shops.huoye.operation.fragment.SellOrderFragment;
import huoye.shops.huoye.operation.model.ShopProductList;
import huoye.shops.huoye.operation.presenter.ManageProductPresenter;
import huoye.shops.huoye.operation.view.IManageProductRefreshView;
import huoye.shops.huoye.operation.widget.SelectShopAttributeDialog;
import huoye.shops.utils.StockUtils;


public class ManageProductActivity extends BaseActivity{

    public static final int TYPE_SELECT_SHOP_ATTRIBUTE_HK = 2; //黑卡折扣
    public static final int TYPE_SELECT_SHOP_ATTRIBUTE_LM = 3; //联盟折扣
    public static final int TYPE_SELECT_SHOP_ATTRIBUTE_NEW_USER = 1; //新用户折扣
    public static final int TYPE_SELECT_SHOP_ATTRIBUTE_SHOW = 0; //店铺展示
    public static final int TYPE_SELECT_SHOP_ATTRIBUTE_LIMIT = 4; //限时折扣



    @BindView(R.id.base_toolbar_tl)
    TabLayout tl;
    @BindView(R.id.base_toolbar_vp)
    ViewPager vp;



    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    AXIFragmentPagerAdapter myFragmentPagerAdapter;



    @BindView(R.id.operation_manage_btn_add_shop)
    Button btnAddShop;
    @OnClick(R.id.operation_manage_btn_add_shop)
    void onAddShopClick(){
        int iCardType = UserManager.getInstance().getCardType();
        showSelectShop(iCardType);
    }

    @OnClick(R.id.operation_manage_btn_limit_discount)
    void onLimitDiscountClick(){
        int cardType = UserManager.getInstance().getCardType();
        if(cardType == 1 || cardType == 2){
            ProductInfo productInfo = new ProductInfo();
            productInfo.setProductId("0");
            productInfo.setSalePrize("0");
            productInfo.setDisType(TYPE_SELECT_SHOP_ATTRIBUTE_LIMIT);
            startActivity(LimitDiscountActivity.class,productInfo);
        }else {
            makeToast("只有黑卡用户和联盟商家才能创建限时折扣");
        }


    }




    private ManageProductPresenter mManageProductPresenter;




    @Override
    protected int getContentViewId() {
       return R.layout.activity_manage_shop;
    }



    @Override
    protected void initView(@Nullable Bundle bundle) {
        setTitle("商品管理");

        fragments.add(ManageProductFragment.getInstan(ManageProductFragment.TYPE_MANAGE_PRODUCT_ALL));
        fragments.add(ManageProductFragment.getInstan(ManageProductFragment.TYPE_MANAGE_PRODUCT_HKLM));
        fragments.add(ManageProductFragment.getInstan(ManageProductFragment.TYPE_MANAGE_PRODUCT_XSZK));
        fragments.add(ManageProductFragment.getInstan(ManageProductFragment.TYPE_MANAGE_PRODUCT_NEW_USER));


        titles.add(getString(R.string.operation_prpduct_all));
        titles.add(getString(R.string.operation_prpduct_hklm));
        titles.add(getString(R.string.operation_prpduct_xszk));
        titles.add(getString(R.string.operation_prpduct_new_user));

        StockUtils.reflex(tl);
        myFragmentPagerAdapter = new AXIFragmentPagerAdapter(getSupportFragmentManager(),fragments, titles);
        vp.setAdapter(myFragmentPagerAdapter);
        vp.setOffscreenPageLimit(fragments.size());
        tl.setupWithViewPager(vp);

    }



    private void showSelectShop(int iCardType){
        SelectShopAttributeDialog selectShopAttributeDialog = new SelectShopAttributeDialog(this,iCardType);
        selectShopAttributeDialog.setOnSelectShopAttributeListener(new SelectShopAttributeDialog.OnSelectShopAttributeListener() {
            @Override
            public void onSelectShopAttributeClick(int shopType) {
                ProductInfo productInfo = new ProductInfo();
                productInfo.setProductId("0");
                productInfo.setSalePrize("0");
                productInfo.setDisType(shopType);
                startActivity(LimitDiscountActivity.class,productInfo);

            }
        });
        selectShopAttributeDialog.show();
        selectShopAttributeDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失.
    }


    @Override
    protected void onTopLeftBtnClick() {
        super.onTopLeftBtnClick();
        finish();
    }

}
